package homework12月4号;

import java.util.Scanner;

public class H1 {
    public static void main(String[] args) throws Exception {
        System.out.println("请输入字符串");
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        System.out.println( stringToNumber(s));
    }
    public static int stringToNumber(String s) throws Exception {
        int a = 0;
        if (s.equals(null)){
            throw new Exception("字符串不能为null");
        }else if (s.equals("")){
            throw new Exception("字符串不能为空");
        }
        try {
            a = Integer.parseInt(s);
        } catch (Exception e) {
            throw new Exception("字符串转换失败");
        }
        return a;
    }
}
